Hash algorithms are simple in implementation and perform at a fast speed, so hash algorithms are used in areas such as data retrieval and data membership determination. In a router, hash algorithms are generally used for exact match tables, such as Media Access Control (MAC) table, the table of black and white lists and the flow table.
For different exact match tables, the hash algorithms need to use different hash tables. For example, when a Key to be searched for is long, the hash algorithm chooses a hash table that includes a hash index table and an original Key table, as shown in FIG. 1. A hash fingerprint of the Key and an index to an original Key are stored in the hash index table; and the original Key is stored in the original Key table. The original Key corresponds to the original Key index in one-to-one correspondence. When the Key to be searched for is short, the hash algorithm chooses a hash table structure with only the original Keys.
For different exact match tables, the hash algorithms need to use different hash. tables. For example, the flow table and the table of black and white lists in the router need to establish different hash table structures. Keys in the table of black and white lists are part of Keys in the flow table. However, the same part of the Keys still needs to be stored in both hash tables. In this way, in a process for storing and searching a plurality of hash tables of Keys having common parts, the common parts are stored many times, so that the storage space is wasted.